<?php

use backend\components\helper\EasyHtml;
use backend\components\widget\adminLTE\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\search\UserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title                   = '管理员列表';
$this->params['breadcrumbs'][] = $this->title;
?>
<style>
    div.admin-image{
        display: inline-block;
        width: 45px;
        height: 45px;
        margin-right: 2px;
    }
    .admin-image .admin-avatar{
        width: 100%;
        border: 1px solid #d2d6de;
        border-radius: 50%;
    }
    div.admin-info{
        vertical-align: middle;
        display: inline-block;
    }
    div.admin-info span{
        display: block;
        text-align: left;
    }
</style>
<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header with-border">
                <h3 class="box-title"><?= EasyHtml::encode($this->title) ?></h3>
                <div class="box-tools pull-right">
                    <?= EasyHtml::iconLink('新增', ['create'], [
                        'icon' => 'plus',
                        'class' => 'btn btn-success',
                    ]) ?>
                </div>
            </div>
            <div class="box-tools form-inline">
                <?php echo $this->render('_search', ['model' => $searchModel]); ?>
                <div class="box-body">
                    <?= GridView::widget([
                        'dataProvider' => $dataProvider,
                        'columns'      => [
                            ['class' => 'yii\grid\SerialColumn', 'header' => '序号'],
                            [
                                'format' => 'raw',
                                'label' => '账号信息',
                                'value' => function($model){
                                    return '<div class="admin-image">'.
                                                EasyHtml::img($model->admin_avatar,['class'=>'admin-avatar']).
                                            '</div>'.
                                            '<div class="admin-info">'.
                                                EasyHtml::tag('span','编号:'.$model->id,['class'=>'text-success']).
                                                EasyHtml::tag('span','账号:'.$model->username,['class'=>'text-danger']).
                                            '</div>';

                                },
                            ],
                            //'id',
                            //'username',
                            //'admin_avatar',
                            //'password_hash',
                            //'password_reset_token',
                            'email:email',
                            //'auth_key',
                            [
                                'label' => '启用',
                                'class' => \nickdenry\grid\toggle\components\RoundSwitchColumn::class,
                                'attribute' => 'status',
                                'headerOptions' => ['width' => 150],//列长
                            ],
                            [
                                'format' => 'raw',
                                'label' => '登录信息',
                                'value' => function($model){
                                    return '<div class="admin-info">'.
                                        EasyHtml::tag('span','登录ip:'.long2ip($model->login_ip),['class'=>'text-success']).
                                        EasyHtml::tag('span','登录次数:'.$model->login_num,['class'=>'text-danger']).
                                        '</div>';
                                }
                            ],
                            [
                                'format' => 'raw',
                                'label' => '时间',
                                'value' => function($model){
                                    return '<div class="admin-info">'.
                                            EasyHtml::tag('span','创建时间:'.$model->created_at,['class'=>'text-success']).
                                            EasyHtml::tag('span','登录时间:'.$model->login_at,['class'=>'text-danger']).
                                        '</div>';
                                }
                            ],
                            //'updated_at',
                            //'created_at',
                            [
                                'class' => 'backend\components\widget\adminLTE\ActionColumn',
                                'buttons' => [
                                    'view' => function($url, $model) {
                                        return EasyHtml::iconLink('权限', ['/auth/assignment/view','id'=>$model->id],[
                                            'icon' => 'list',
                                            'class' => 'btn btn-xs btn-primary'
                                        ]);
                                    }
                                ],
                            ],
                        ],
                    ]); ?>
                </div>
            </div>
        </div>
    </div>
</div>
